import { setBIMBaseToken, clearBIMBaseToken } from './utils.js';
import { BIMBaseLogin } from './api.js';

export async function login(akskPair) {
	// const akskPair_demo = {
	// 	station_name: 'fakeBimBase',
	// 	engine_type: 'BIMBase',
	// 	ak: 'BIMBase',
	// 	sk: 'acmesecret'
	// };
	try {
		const res = await BIMBaseLogin(akskPair.origin, akskPair.ak, akskPair.sk);
		setBIMBaseToken(akskPair.stationName, res.access_token);
	} catch (err) {
		clearBIMBaseToken(akskPair.stationName);
		throw err;
	}
}
